package com.feign.core.mybatis;

import jakarta.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;


/**
 * 表元数据监听器,启动时加载表元数据
 */
@Component
public class TableMetadataEventListener implements ApplicationListener<ContextRefreshedEvent> {

    private final TableMetadataService tableMetadataService;

    @Autowired
    public TableMetadataEventListener(TableMetadataService tableMetadataService) {
        this.tableMetadataService = tableMetadataService;
    }

    @Override
    public void onApplicationEvent(@Nonnull ContextRefreshedEvent event) {
        // 在应用上下文刷新后加载表元数据
        tableMetadataService.loadTableMetadata();
    }
}
